package com.rany.day10.demo03;

import java.io.FileNotFoundException;
import java.io.IOException;

public class IOExceptionTest {
    public static void main(String[] args) throws IOException {
        readFile("C://hash");
       // testFile("D://hash.txt");
       // readFile("E://map");
        try{
            readFile("E://map");
        }catch (IOException e){
            System.out.println("这是异常代码");
            String message = e.getMessage();
            System.out.println(message);
            e.printStackTrace();
        }finally {
            System.out.println("________");
            System.out.println("后续代码正常执行");
        }
    }

    private static void testFile(String name) throws IOException {
        if (!name.endsWith(".doc")){
            throw new IOException("文件格式异常");
        }
    }

    private static void readFile(String fileName) throws FileNotFoundException {
        if (!fileName.equals("C://hash")){
            throw new FileNotFoundException("文件目录异常");
        }
    }
}
